<cfcomponent output="false">

    <cfscript>
    this.Name = "EPAR";
    this.ApplicationTimeout = CreateTimeSpan( 0, 0, 1, 0 );
    this.SessionManagement = true;
    this.SetClientCookies = false;
    this.Datasource = "EPAR";
    this.ormenabled = true;
    this.ormsettings = {
        logsql = true,
        dbcreate = "none",
        cfclocation = "models"
    };
    </cfscript>
    
    <cffunction name="OnApplicationStart" access="public" returntype="boolean"  output="false" >
        <cfscript>        
            APPLICATION.version = "1.0";
            return true;        
        </cfscript>
    </cffunction>


    <cffunction name="OnApplicationEnd" access="public" returntype="void" output="false" >
        <cfargument name="ApplicationScope" type="struct" required="false" default="#StructNew()#" />

        <cfreturn />
    </cffunction>
    
    
    <cffunction name="OnSessionStart" access="public" returntype="void" output="false" >
               
        <cfinclude template="/code_lib/SCF_Employee.cfm">
	    <cfinclude template="/code_lib/SCF_HR.cfm">
	    <cfinclude template="/code_lib/SCF_REGEX.cfm">
        
        <cfset Session.UserID = ListGetAt(CGI.Auth_User,2,'\')>
		<cfset Session.EmpInfo = SCF_Employee_GetEmpInfo_FromLogin(CGI.Auth_User)>
		<cfset Session.UserRosettaID = Session.EmpInfo.MasterID>
		<cfset Session.HRID = SCF_HR_MasterID_to_HRPersonID(Session.EmpInfo.MasterID)>
		<cfset Session.ADMIN = "ADMIN">
		<cfset Session.HR = "HR">
		<cfset Session.IT = "IT">
		<cfset Session.FINANCE = "FINANCE" />
		<cfset Session.FACILITIES = "FACILITIES" />
		<cfset Session.MANAGERS = "MANAGERS" />
		<cfset Session.LIAISONS = "LIAISONS" />
		<cfset Session.bolManager = False />
		<cfset Session.SERVICEDESK_EMAIL = "bfrick@scf.cc" />
		<cfset Session.ITS_EMAIL = "bfrick@scf.cc" />
		<cfset Session.FormComments = "" />
		<cfset Session.StepConfirmation = "" />
		<cfset Session.DataSource = "EPAR" />
		<cfset Session.DataSourceWFCDB = "KRONOS" />
		<cfset Session.DataSourceRosetta = "RosettaStone" />
		<cfset Session.DataSourceAccessControl = "AccessControl" />
		<cfset Session.DataSourceSCF_General = "SCF_General" />        
        <cfset Session.SearchString = "Search" />
		
        <cfscript>
            session.rootDir = ListGetAt(CGI.PATH_INFO,1,"/");
            session.StaticPages = ListGetAt(CGI.PATH_INFO,1,"/") & "/static/";          
            session.mediaDir = ListGetAt(CGI.PATH_INFO,1,"/") & "/media/";
            session.TerminationDocuments = "\\scfweb1temp\e$\CFMX\SCF Intranet\epar\media\Documents\Termination\";
            
            AD = CreateObject("component", "code_lib.SCF_ActiveDirectory");
            /*UserQuery = new query();
            UserQuery.setAttributes(GetAllUsers = AD.getAllUsers() );
            UserQuery.setcachedwithin(CreateTimeSpan(0, 0, 20, 0));
            UserQuery = UserQuery.execute(sql="SELECT * FROM GetAllUsers", dbtype="query");*/
            /*session.AllADUsers = UserQuery.getResult();*/
            UserGroups = AD.getUserAttributesByDN(AD.getUserDNByAccountName(Session.UserID));
        </cfscript>
        
		<!---<cfldap 
		    action="query" 
		    attributes="memberOf, displayname"
		    filter="(sAMAccountName=#Session.UserID#)"
		    username="userlist" 
		    password="DefinedMan" 
		    name="UserGroups" 
		    start="OU=SCFUsers,DC=Southcentralfoundation,DC=COM" 
		    server="10.100.1.101">
        --->
        
        <cfquery name="qryGroupCheckManagers" dbtype="query">
		    Select * from UserGroups
		    Where memberOf like '%SCF Managers DL%' or memberOf like '%Hiring Delegates%'
		</cfquery>

	    <cfquery name="qryGroupCheckIT" dbtype="query">
	        Select * from UserGroups
	        Where memberOf like '%SCF Information Technology Services%'
	    </cfquery>
	    
	    <cfquery name="qryGroupCheckHR" dbtype="query">
	        Select * from UserGroups
	        Where memberOf like '%SCF Human Resources%'
	    </cfquery>
	    
	    <cfquery name="qryGroupCheckFN" dbtype="query">
	        Select * from UserGroups
	        Where memberOf like '%SCF Finance Operations%'
	    </cfquery>
	    
	    <cfquery name="qryGroupCheckFA" dbtype="query">
	        Select * from UserGroups
	        Where memberOf like '%SCF Facilities%'
	    </cfquery>
                    
        <cfquery name="qryGroupCheckCL" dbtype="query">
            Select * from UserGroups
            Where memberOf like '%SCF Contract Liaisons%'
        </cfquery>
		
		<cfif qryGroupCheckIT.recordcount GT 0>
		    <cfset Session.Auth =True>
		    <cfset Session.strAuthType =Session.IT>
		<cfelseif qryGroupCheckHR.recordcount GT 0>
		    <cfset Session.Auth =True>
		    <cfset Session.strAuthType = Session.HR>
		<cfelseif qryGroupCheckFN.recordcount GT 0>
		    <cfset Session.Auth =True>
		    <cfset Session.strAuthType =Session.FINANCE>
		<cfelseif qryGroupCheckFA.recordcount GT 0>
		    <cfset Session.Auth =True>
		    <cfset Session.strAuthType =Session.FACILITIES>
		<cfelseif qryGroupCheckCL.recordcount GT 0> 
		    <cfset Session.Auth =True>
		    <cfset Session.strAuthType = Session.LIAISONS>
		<cfelseif qryGroupCheckManagers.recordcount GT 0> 
		    <cfset Session.Auth =True>
		    <cfset Session.strAuthType = Session.MANAGERS>
		<cfelse>
		    <cfset Session.Auth =False>
		    <cfset Session.strAuthType ="">
		</cfif>
		
		<cfif Session.strAuthType NEQ "" AND Session.strAuthType NEQ Session.MANAGERS>
		    <!--- Check to see if they are additionally in the managers group--->
		    <cfif qryGroupCheckManagers.recordcount GT 0> 
		        <cfset Session.Manager = True>
		    </cfif>
		</cfif>

        
        <cfreturn />
    </cffunction>


    <cffunction name="OnRequestStart" access="public" returntype="boolean" output="false" >
		<cfargument name="targetPage" type="string" hint="The page requested" required="true"/>
        <!---<cfset ORMReload() />--->
		<cfreturn true>
    </cffunction>


    <cffunction name="OnRequest" access="public" returntype="void" output="true" >
        <cfargument name="TargetPage" type="string" required="true" />
        
        <cfinclude template="#ARGUMENTS.TargetPage#" />

        <cfreturn />
    </cffunction>


    <cffunction name="OnRequestEnd" access="public" returntype="void" output="true" >

        <cfreturn />
    </cffunction>


    <cffunction name="OnSessionEnd" access="public" returntype="void" output="false">
        <cfargument name="SessionScope" type="struct" required="true" />
        <cfargument name="ApplicationScope" type="struct" required="false" default="#StructNew()#" />


        <cfreturn />
    </cffunction>


     <cffunction name="OnError" access="public" returntype="void" output="true">
        <cfargument name="Exception" type="any" required="true" />
        <cfargument name="EventName" type="string" required="false" default="" />
        <cfscript>
            developerEMail = "bfrick@scf.cc";  // Your e-mail here, or SCFAppNotifyAdmin@scf.cc

            WriteLog(type="Error", text="#UCase(Exception.Type)# ERROR:  #Exception.Message#    LOCATION: #CGI.SERVER_NAME##CGI.SCRIPT_NAME#, Line #Exception.TagContext[1].Line#.");
                
            // E-Mail the Error
            mail=new mail();
            mail.setType("html");
            mail.setFrom("Your Friendly ColdFusion Server <noreply@scf.cc>");
            mail.setTo(developerEMail);         
            mail.setSubject("Doh! Error in #APPLICATION.ApplicationName#");
            savecontent variable="eMailBody" {
                include "/code_lib/SCF_Standard_Error_EMail.cfm";
            }
            mail.addPart(type="html", charset="utf-8", body="#eMailBody#");
            mail.send();
                
            // Display the Error
            include "/code_lib/SCF_Standard_Error_Display.cfm";
                
            // Throw the Error (for Dev Only)
            throw(ARGUMENTS.Exception);

        </cfscript>
       <cfreturn />
    </cffunction> 


</cfcomponent> 